package com.wlhse.controller;

import com.wlhse.entity.TaskAndProcessPojo;
import com.wlhse.service.TaskAndProcessService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("TaskAndProcessController")
@RequestMapping("/api/v3")
//检查工序配置
public class TaskAndProcessController {
    @Resource
    private TaskAndProcessService taskAndProcessService;

    @RequestMapping(value = "/task_and_process/tree", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getChirdren() {
        return taskAndProcessService.getTaskAndProcessTree();
    }

    @RequestMapping(value = "/task_and_process", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getTaskAndProcess(@RequestParam(value = "code", required = false) String code) {
        return taskAndProcessService.getTaskAndProcessList(code);
    }

    // 增
    @RequestMapping(value = "/task_and_process", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addTaskAndProcess(@RequestBody(required = false) TaskAndProcessPojo taskAndProcessPojo) {
        return taskAndProcessService.insertTaskAndProcess(taskAndProcessPojo);
    }

    // 删 by nodeCode
    @RequestMapping(value = "/task_and_process", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteTaskAndProcess(@RequestBody(required = false) TaskAndProcessPojo taskAndProcessPojo) {
        return taskAndProcessService.deleteTaskAndProcess(taskAndProcessPojo.getTaskAndProcessCode());
    }

    // 改
    @RequestMapping(value = "/task_and_process/{id}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String UpdateTaskAndProcess(@PathVariable int id, @RequestBody(required = false) TaskAndProcessPojo taskAndProcessPojo) {
        taskAndProcessPojo.setTaskAndProcessId(id);
        return taskAndProcessService.updateTaskAndProcess(taskAndProcessPojo);
    }

}
